class Solution
{
public:
    int pivotIndex(vector<int> &nums)
    {
        int sum = accumulate(nums.begin(), nums.end(), 0);
        int partialSum = 0;
        for (int i = 0; i < nums.size(); ++i)
        {
            if (sum == 2 * partialSum + nums[i])
            {
                return i;
            }
            partialSum += nums[i];
        }
        return -1;
    }
};